// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: GHZ Setup Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//

private alias object.value0 : object.timer
private alias object.value1 : object.index

private alias object.value2 : object.drawX
private alias object.value3 : object.drawY
private alias object.value4 : object.letter
private alias object.value5 : object.charamount
private alias object.value6 : Object.MenuChoose

private alias object.value7 : object.fadetimer

private alias object.value8 : Object.TouchTimer


public value BoxPositionY = 0;
public value CharacterTalking = 0;
public value TextActive = 0;
public value CutsceneActive = 0;

reserve function TextDrawing

function TextDrawing
	temp0 = object.drawX
	temp1 = object.charamount
	while temp1 > 0
	// Get the actual character at the current char pos
	GetTextInfo(object.letter, 1, TEXTINFO_TEXTDATA, Object.Index, ArrayPos0)

	Object.Frame = 0
	
	// Take uppercase letters and turn them into a matching Sprite Frame
	if object.letter > 64
		if object.letter < 91
			Object.Frame  = object.letter
			Object.Frame -= 64
		end if
	end if
	
	// Take lowercase letters and turn them into a matching Sprite Frame
	if object.letter > 96
		if object.letter < 123
			Object.Frame  = object.letter
			Object.Frame -= 96
		end if
	end if

		//ASCII Table required!
		switch object.letter
			case 33	//!
				ArrayPos0++
				temp1--
				object.drawX += 0x69
				break		

			case 48	;DrawSpriteScreenFX(44, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//0
			case 49	;DrawSpriteScreenFX(45, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//1
			case 50	;DrawSpriteScreenFX(46, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//2
			case 51	;DrawSpriteScreenFX(47, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//3
			case 52	;DrawSpriteScreenFX(48, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//4
			case 53	;DrawSpriteScreenFX(49, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//4
			case 54	;DrawSpriteScreenFX(50, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//4
			case 55	;DrawSpriteScreenFX(51, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//4
			case 56	;DrawSpriteScreenFX(52, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//4
			case 57	;DrawSpriteScreenFX(53, FX_INK, object.drawX, object.drawY) ;ArrayPos0++ ;object.charamount-- ;object.drawX += 0x8 ;break	//4

			case 64	//@	LINE SKIPPER
				object.drawY += 16
				object.drawX = temp0
			

				// Move to the next letter
				ArrayPos0++
				
				// And decrease the remaining letter count, as well
				temp1--
			break
			default
			// Notably, the space character (32) is skipped over here, as it shouldn't draw anything
			

			DrawSpriteScreenFX(Object.Frame, FX_INK, object.drawX, object.drawY)

			// Move to the next letter
			ArrayPos0++
			
			// And decrease the remaining letter count, as well
			temp1--
			
			// Each letter should be spaced 8 pixels apart
			object.drawX += 0x8
			break
		end switch
	loop
end function

//if being stupid was a job

event ObjectMain
	switch object.state
	case 0
		Object.Index = 4
		object.charamount = 0
		if object[2].state == 4
			object.state++
			object.timer = 0
		end if
	break
	case 1
		if object.alpha < 255
			object.alpha += 8
		end if	
		GetTextInfo(temp0, 1, TEXTINFO_TEXTSIZE, Object.Index, 0)
		if object.charamount != temp0
			object.charamount++
		end if
	break
	end switch
end event

event ObjectDraw
	object.inkEffect = INK_ALPHA
	

	ArrayPos0 = 0	//starting letter

	object.drawY = 160
	
	temp3 = screen.xsize
	temp3 -= screen.xcenter
	temp3 += 90

	object.drawX = temp3

	temp1 = screen.xcenter
	temp1 -= 28

//	DrawSpriteScreenFX(34, FX_INK, temp1, 50)

//	Callfunction(TextDrawing)
end event

event ObjectStartup

	LoadSpriteSheet("FNAF/Objects1.gif")

	switch saved.language
		case 0
			LoadTextFile(1, "Data/Game/FreddyMenu.txt")
		break
		case 1	//PTBR
			LoadTextFile(1, "Data/Game/FreddyMenu.txt")
		break
		case 2 //ES
			LoadTextFile(1, "Data/Game/Spanish/FreddyMenu.txt")
		break
		case 3 //French
			LoadTextFile(1, "Data/Game/French/FreddyMenuFR.txt")
		break
	end switch

	SpriteFrame(0, 0, 0, 0, 0, 0)	//0 the bar

	// #1 -> #34 - Alphabet
	// (Using loops to automate Sprite Framing)

	//not related too stuff in objectdraw

	//temp7: starting ypos, progresses by 17 and stops before 100, because theres only 3 rows
	//temp6: starting xpos, the letter A
	temp1 = 49
	while temp1 < 100
		temp0 = 549
		while temp0 < 648
			SpriteFrame(-3, -6, 8, 16, temp0, temp1)
			temp0 += 9
		loop
		temp1 += 17
	loop

	//fred head
	SpriteFrame(-3, -6, 64, 64, 513, 117) //35

	//options
	SpriteFrame(-3, -6, 64, 57, 888, 1) //36

	//continue, new game, main menu
	SpriteFrame(-3, -6, 64, 11, 956, 1) //37
	SpriteFrame(-3, -6, 64, 11, 956, 24) //38
	SpriteFrame(-3, -6, 64, 11, 956, 47) //39

	SpriteFrame(-3, -6, 202, 217, 821, 560) //40

	SpriteFrame(-3, -6, 40, 7, 847, 1) //41	

	SpriteFrame(-3, -6, 91, 34, 888, 59) //42

	SpriteFrame(-3, -6, 91, 11, 888, 94) //43

	SpriteFrame(-3, -6, 91, 11, 888, 117) //44



	//#45 - idk numbers
	temp1 = 49
	while temp1 < 100
		temp0 = 513
		while temp0 < 549
			SpriteFrame(-3, -6, 8, 16, temp0, temp1)
			temp0 += 9
		loop
		temp1 += 17
	loop

	SpriteFrame(-3, -6, 64, 64, 513, 182) //56

	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[4].Type = TypeName[Controls]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[4].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[4].DrawOrder = 6

end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("IIZ/Objects1.gif")
	SpriteFrame(0, 0, 64, 64, 153, 154)
end event
